<?php
/**
 * Created by PhpStorm.
 * User: iamya
 * Date: 2017/10/9
 * Time: 15:48
 */

namespace app\circle\model;

class CircleModel extends BaseModel
{
    protected $name = 'circle_circle'; //定义用户表
    //开启自动写入时间戳
    protected $autoWriteTimestamp = true;
    // 定义自动完成的属性
    protected $auto = []; //新增修改
    protected $insert = []; //插入
    protected $update = []; //修改
    //类型自动转换
    protected $type = [];
    protected $append=['circle_mcount','circle_thcount'];

    /*读取器*/
    public function getMemberCircle($memberId)
    {
        $memberModel=new CircleMemberModel();
        $circle=$memberModel->field('circle_id,circle_name')->where('member_id',$memberId)->where('cm_state',1)->select();
        return $circle->toArray();
    }

    public function getCircleMcountAttr($value,$data)
    {
        $memberModel=new CircleMemberModel();
        return $memberModel->where('circle_id',$data['circle_id'])->count();
    }

    public function getCircleThcountAttr($value,$data)
    {
        $themeModel=new ThemeModel();
        return $themeModel->where('circle_id',$data['circle_id'])->count();
    }
    /*修改器*/

}